<#include "head_bus.ftl">
<!--内容开始-->
<div class="container">
    <ol class="breadcrumb">
      <li><a href="#">首页</a></li>
      <li><a href="#">个人中心</a></li>
      <li class="active">个人信息完善</li>
    </ol>
    <div class="p-content">
        <form class="form-horizontal" id="myForm" role="form">
           <div class="form-group">
              <label class="col-sm-6 col-xs-4 control-label">公司名称：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="company" value="${userinfo.company!''}" id="company" onblur="companyName()">
              </div>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">通讯地址：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="address" value="${userinfo.address!''}" id="address">
              </div>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">传真号码：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="fax" value="${userinfo.fax!''}" id="fax" onblur="companyName()">
              </div>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">联  系  人：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="realname" value="${userinfo.real_name!''}" id="real_name">
              </div>
             <span class="colR f12">* 必填项</span>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">移动电话：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="dh" value="${userinfo.dh!''}" id="dh">
              </div>
              <span class="colR f12">* 必填项</span>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">邮        箱：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="lxmall" value="${userinfo.lx_mall!''}" id="lx_mall">
              </div>
              <span class="colR f12">* 必填项</span>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">身份证号：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="personId" value="${userinfo.person_id!''}" id="personId">
              </div>
              <span class="colR f12">* 必填项</span>
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">户口所在地：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="hukouAddr" value="${userinfo.hukou_addr!''}" id="hukouAddr">
              </div>
              <span class="colR f12">* 必填项</span>
           </div>
           <hr>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">开  户  名：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="bankusername" value="${userinfo.bank_username!''}" id="bank_username">
              </div>
               <span class="colR f12">* 必填项</span>             
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">银行账号：</label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" name="bankcard" value="${userinfo.bank_card!''}" id="bank_card" onblur="bankCard()">
              </div>
             <span class="colR f12">* 必填项</span>              
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label">开户银行：</label>
              <div class="col-sm-3  col-xs-4">
                 <input type="text" class="form-control"  placeholder="省（市）" id="province">
              </div>
              <div class="col-sm-3  col-xs-4">
                 <input type="text" class="form-control"  placeholder="市（区县）" id="city">
              </div>            
           </div>
           <div class="form-group">
              <label class="col-sm-6  col-xs-4 control-label"> </label>
              <div class="col-sm-5  col-xs-6">
                 <input type="text" class="form-control" placeholder="支行/分处理"  id="bank_name" readonly>
              </div>
             <span class="colR f12">* 必填项</span>              
           </div>
           
           <input type="hidden" id="bankname" name="bankname"/>
           <div class="form-group">
              <div class="text-right">
                  <button type="button" class="btn btn-180" onclick="save()">保存</button>
                  <button type="button" class="btn btn-180 reset ml100" onclick="resetInput()">重置</button>
              </div>
          </div>
        </form>
    </div>  
</div>
<script>

window.onload=function(){
	$("title").html("个人中心-个人信息完善");
	var bankname='${userinfo.bank_name!""}';
	if(''!=bankname){
		var arr=bankname.split(";");
		if(arr.length>1){
			$("#province").val(arr[0]);
			$("#city").val(arr[1]);
			$("#bank_name").val(arr[2]);
		}else{
			$("#bank_name").val(bankname);
		}
	}
}
//银行卡验证以及开户行
function bankCard(){
	var bankCard = $('#bank_card').val(); //银行账号
	var array=[[/^(\d{16}|\d{19})$/,bankCard,"银行帐号格式不正确！"]];
		for(var	 i=0;i<array.length	;i++)
		{
			if(array[i][0].test(array[i][1])==false)
			{
				alert(array[i][2]);
				return;
			}
		}
            if (bankCard == null || bankCard == "") {
            	alert("银行卡号不能为空");
                return "";
            }
            $.getJSON("${BASE_PATH}/static/business/js/bankData.json", {}, function (data) {
                var bankBin = 0;
                var isFind = false;
                for (var key = 10; key >= 2; key--) {
                    bankBin = bankCard.substring(0, key);
                    $.each(data, function (i, item) {
                        if (item.bin == bankBin) {
                            isFind = true;
                            $("#bank_name").val(item.bankName);
                            //return item.bankName;
                        }
                    });

                    if (isFind) {
                        break;
                    }
                }

                if (!isFind) {
                    return "未知发卡银行";
                }
            });
}
function companyName(){
	var flag=true;
	var company = $('#company').val(); //公司名称
	if(''!=company){
		var array=[[/^[A-z|\u4e00-\u9fa5]+$/,company,"公司名称填写不正确，请输入中文或字母!"]];
		for(var	 i=0;i<array.length	;i++)
		{
			if(array[i][0].test(array[i][1])==false)
			{
				alert(array[i][2]);
				flag=false;
			}
		}
	}
	var fax = $('#fax').val(); //传真号码
	if(''!=fax){
		var checkFax = /^(\d{3,4}-)?\d{7,8}$/; 
		if(!checkFax.test(fax)){
			alert("传真格式不正确，传真格式为:xxx-12345678或xxxx-1234567或xxxx-12345678");
			flag=false;
		}
	}
	return flag;
}
function resetInput(){
	$("input").each(function(){
		$(this).val("");
	});
}
function save(){
		var company = $('#company').val(); //公司名称
		var address = $('#address').val(); //通讯地址
		var fax = $('#fax').val(); //传真号码
		if(''!=company ||''!=fax){
			if(!companyName()){
				return;
			}
		}
		var realname = $('#real_name').val(); //联  系  人
		if(''==realname){
			alert("联系人不能为空");
			return;
		}
		var dh = $('#dh').val(); //移动电话
		var lxmall = $('#lx_mall').val(); //邮箱
		var bankusername = $('#bank_username').val(); //开  户  名
		if(''==bankusername){
			alert("开户名不能为空");
			return;
		}
		var bankcard = $('#bank_card').val(); //银行账号
		var personid = $('#personId').val(); //身份证号
		var hukouAddr =$('#hukouAddr').val(); //户口所在地
		if(''==hukouAddr){
			alert("户口所在地不能为空");
			return;
		}
		
		
		var province=$('#province').val(); //省
		var city=$('#city').val(); //市
		if(''!=province && ''==city){
			alert("请填写完整的市（区县）");
			return;
		}
		if(''==province && ''!=city){
			alert("省（市）");
			return;
		}
		var bankname =$('#bank_name').val();
		
		if(''==bankname){
			alert("开户行不能为空");
			return;
		}else{
			if(''!=province && ''!=city){
				bankname=province+";" + city +";"+ $('#bank_name').val();//开  户  名
			}else{
				bankname=$('#bank_name').val();
			}
		}
		
		$("#bankname").val(bankname);
		var array=[[/^[1-9][\d]{10}?$/,dh,"联系电话格式不正确，请输入11位手机号"],[/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.com)|(.cn)+/,lxmall,"邮箱格式不正确！"],[/^(\d{15}|\d{18})$/,personid,"身份证格式不正确！"],[/^[A-z|\u4e00-\u9fa5|1-9]+$/,realname,"联系人格式不正确，请输入中文或字母或非零数字!"]];
		for(var	 i=0;i<array.length	;i++)
		{
			if(array[i][0].test(array[i][1])==false)
			{
				alert(array[i][2]);
				return;
			}
		}
		$.ajax({
	            cache: true,
	            type: "POST",
	            url:"${BASE_PATH}/user/account.json",
	            dataType : 'json',
	            //data:{company:company,address:address,fax:fax,realname:realname,dh:dh,lxmall:lxmall,bankusername:bankusername,bankname:bankname,bankcard:bankcard},
	            data:$("#myForm").serialize(),
	            async: false,
	            success: function(data){
	               if(data.status==1){
	               		alert(data.info);
	               }
	            }
	        });
	}
</script>
<#include "foot_bus.ftl">